package dao;

import org.hibernate.Query;
import org.hibernate.criterion.Restrictions;

import dominio.Usuario;

public class UsuarioDao extends GenericDAO<Usuario>{
	
	public Usuario buscarPorLogin(String login){
		Usuario user = (Usuario) getSession().createCriteria(Usuario.class).add(Restrictions.eq("login", login).ignoreCase()).uniqueResult();				 
		String hql = "update Usuario set ultimoAcesso = NOW() where idUsuario = :p2";			
        Query query = getSession().createQuery(hql);
        //query.setDate("p1", new Date((new java.util.Date()).getTime()));
        query.setInteger("p2", user.getIdUsuario());
        int rowCount = query.executeUpdate();    
        if(rowCount > 0)System.out.println("Sucesso ao atualizar ultimo acesso");
        closeEntityManager();
        return user;
	}	

}